import 'dart:convert';

import 'package:flutter_chubao/models/model_user.dart';
import 'package:flutter_chubao/tools/app_log.dart';
import 'package:flutter_chubao/tools/shared/app_shared.dart';

class AppSharedStorage {
  static Future<UserEntity> getUserInfoLocal() async {
    var userInfo = AppSharedPro.getString(AppShareConstant.userInfo);
    if (userInfo.isNotEmpty) {
      var userData = json.decode(userInfo);
      return UserEntity.fromJson(userData);
    } else {
      return UserEntity();
    }
  }

  static saveUserInfo(UserEntity userEntity) async {
    bool isSucc = await AppSharedPro.setString(
        AppShareConstant.userInfo, jsonEncode(userEntity.toJson()));
    DLog(isSucc);
    if ((userEntity.token ?? '').isNotEmpty) {
      AppSharedPro.setString(
          AppShareConstant.userToken, userEntity.token ?? '');
    }
  }
}
